<html>
    <head><title>upload file</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    </head>
    <body>
        <form action="test.php" method="post" enctype="multipart/form-data">
            <input type="hidden" name="MAX_FILE_SIZE" value="2097152"/>
            <input type="file" name="fileName[]"  multiple="multiple" accept="image/jpeg,image/gif,image/png,application/x-MS-bmp,text/plain,text/html" /><br><br>
            <input type="submit" value="上传文件"/>
        </form>
    </body>
</html>

<?php

function getFiles(){

    $i=0;
    foreach ($_FILES as $file) {

        if (is_array($file['name'])) {

            foreach($file['name'] as $key=>$value){
                $files[$i]['name']=$file['name'][$key];
                $files[$i]['type']=$file['type'][$key];
                $files[$i]['tmp_name']=$file['tmp_name'][$key];
                $files[$i]['size']=$file['size'][$key];
                $files[$i]['error']=$file['error'][$key];
                $i++;
                # code...
            }
        }elseif (is_string($file['name'])) {

            $files[$i]=$file;
            $i++;
            # code...
        }
         # code...
     }

     return $files;
}

function uploadFiles($files,$path='uploads',$maxsize=2097152){ 
    $result=array();
                     
    if ($files['error']===UPLOAD_ERR_OK) {
        if ($files['size']>$maxsize) {

            $result['msg']=$files['name'].'文件过大';
            # code...
        }

        $ext=@strtolower(end(explode('.', $files['name'])));
        $extarray=array('gif','jpeg','jpg');
        if (!in_array($ext, $extarray)) {

            $result['msg']=$files['name'].'文件格式不正确';
            # code...
        }

        $check= true;
        if ($check) {
            
            if(@!getimagesize($files['tmp_name'])){

                $result['msg']=$files['name'].'不是真正的图片';
            }
            # code...
        }

        //判断是否是通过HTTP Post上传
        if (!is_uploaded_file($files['tmp_name'])) {

            $result['msg']=$files['name'].'不是通过HTTP POST上传';
            # code...
        }

        if($result) return $result;//返回$result;

        //$path='uploads';
        if (!file_exists($path)) {

            mkdir($path,0777,true);
            chmod($path, 0777);
            # code...
        }

        $newname=md5(uniqid(microtime(true),true)).'.'.$ext;
        $destination=$path.'/'.$newname;

        if(!move_uploaded_file($files['tmp_name'], $destination)){

            $result['msg']=$files['name'].'文件移动失败';

        }

        $result['msg']=$files['name'].'上传成功';

        $result['dest']=$destination;
        
        return $result;

    }else{
        switch($files['error']){
            case 1:
                $result['msg']=$files['name']. "文件超过了php.ini中upload_max_filesize选项限制的值。";
                 break;
               
               case 2:
                   $result['msg']=  $files['name']."文件的大小超过了HTML表单中max_file_size选项指定的值。";
                   # code...
                   break;
               case 3:
                   $result['msg']=  $files['name']."文件只有部分被上传";
                   # code...
                   break;
               case 4:
                  $result['msg']=  "没有文件被上传";
                   # code...
                   break;
               case 6:
                   $result['msg']=  "找不到临时文件夹。";
                   # code...
                   break;
               case 7:
               case 8:
                   $result['msg']=  "系统出错";
                   # code...
                   break;
        }

        return $result;
    }

    
}

?>

<?php
include('uploads.func.php');

$files=getFiles();

foreach ($files as $value) {

    $result=uploadFiles($value);
    echo $result['msg']."<br/>";
    $uploads[]=@$result['dest'];
}

 $uploads=array_values(array_filter($uploads));
  print_r($uploads);
//当array_filter函数的callback留空时 他会过滤掉所有键值为false的键 
//array_values() 函数返回一个包含给定数组中所有键值的数组，但不保留键名。
?>